Code sample Home

Divide a polyline.
//-----------------------------------------------
void DemoPlineDivide (HANDLE hLcWnd, bool bUseAngle)
{
  HANDLE hBlock, hEnt, hLine, hPnt;
  int    nPoints, np, i;
  double X, Y, Ang, X1, Y1, X2, Y2, L;

  nPoints = 11;
  L = 0.5;  // tick half-length
  // get a block, linked with CAD window
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
  // get selected entity
  hEnt = lcBlockGetFirstSel( hBlock );
  if (hEnt){
    // check if the entity is a polyline
    if (lcEntType( hEnt, LC_ENT_POLYLINE) == TRUE){
      if (bUseAngle){
        np = lcPlineDivide( hEnt, nPoints, TRUE );
        for (i=0; i<np; ++i){
          if (lcGetDivPt( i, &X, &Y, &Ang )){
            lcGetPolarPoint( X, Y, Ang+LC_DEG90, L, &X1, &Y1 );
            lcGetPolarPoint( X, Y, Ang-LC_DEG90, L, &X2, &Y2 );
            hLine = lcBlockAddLine( hBlock, X1, Y1, X2, Y2 );
            lcPropPutInt( hLine, LC_PROP_ENT_COLOR, RGB(255,255,0) );
          }
        }
        // free points buffer
        lcPlineDivide( hEnt, 0, FALSE );
      }else{
        np = lcPlineDivide( hEnt, nPoints, FALSE );
        for (i=0; i<np; ++i){
          if (lcGetDivPt( i, &X, &Y, 0 )){
            hPnt = lcBlockAddPoint( hBlock, X, Y );
            lcPropPutInt( hPnt, LC_PROP_ENT_COLOR, RGB(255,255,0) );
          }
        }
        // free points buffer
        lcPlineDivide( hEnt, 0, false );
      }
      lcBlockUnselect( hBlock );
      lcWndRedraw( hLcWnd ); 
    }
  }  
}


//-----------------------------------------------
void DemoPlineDivide2 (HANDLE hLcWnd, bool bUseAngle)
{
  HANDLE hBlock, hEnt, hLine, hPnt;
  int    nPoints, i;
  double X, Y, Ang, X1, Y1, X2, Y2, L, Delta;

  Delta = 5.0;
  L = 0.5;  // tick half-length
  // get a block, linked with CAD window
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
  // get selected entity
  hEnt = lcBlockGetFirstSel( hBlock );
  if (hEnt){
    // check if the entity is a polyline
    if (lcEntType( hEnt, LC_ENT_POLYLINE) == TRUE){
      if (bUseAngle){
        nPoints = lcPlineDivide2( hEnt, Delta, TRUE );
        for (i=0; i<nPoints; ++i){
          if (lcGetDivPt( i, &X, &Y, &Ang )){
            lcGetPolarPoint( X, Y, Ang+LC_DEG90, L, &X1, &Y1 );
            lcGetPolarPoint( X, Y, Ang-LC_DEG90, L, &X2, &Y2 );
            hLine = lcBlockAddLine( hBlock, X1, Y1, X2, Y2 );
            lcPropPutInt( hLine, LC_PROP_ENT_COLOR, lcColorRGB(255,255,0) );
          }
        }
        // free points buffer
        lcPlineDivide2( hEnt, 0.0, false );
      }else{
        nPoints = lcPlineDivide2( hEnt, Delta, FALSE );
        for (i=0; i<nPoints; ++i){
          if (lcGetDivPt( i, &X, &Y, 0 )){
            hPnt = lcBlockAddPoint( hBlock, X, Y );
            lcPropPutInt( hPnt, LC_PROP_ENT_COLOR, lcColorRGB(255,255,0) );
          }
        }
        // free points buffer
        lcPlineDivide2( hEnt, 0.0, false );
      }
      lcBlockUnselect( hBlock );
      lcWndRedraw( hLcWnd ); 
    }
  }  
}